<?php
// Helper for mod_staffselections.php
defined( '_JEXEC' ) or die( 'Restricted access' );

function get_query()
{
	// Generate random id number
	$db =& JFactory::getDBO();
	$query = "SELECT count('id') FROM #__staffselection";
	$db->setQuery( $query );
	$limit = (int) $db->loadResult();

	// Load the query until it returns a row that is NOT NULL
	do	
	{
		$num = rand( 0, $limit - 1 );
		$query = 
			"SELECT ss.id, ss.title, ss.author, ss.introdescription, ssi.isbn 
				from #__staffselection AS ss INNER JOIN #__staffselectionindex AS ssi
				ON ss.id = '" . $num . "' AND ss.id = ssi.selectionid";
		$db->setQuery( $query );
		$row = $db->loadObject();
	}
	while( $row == null );
	
	return $row;
}


function strip_html_tags( $text )
{	

    $text = preg_replace(
        array(
          // Remove invisible content
            '@<head[^>]*?>.*?</head>@siu',
            '@<style[^>]*?>.*?</style>@siu',
            '@<script[^>]*?.*?</script>@siu',
            '@<object[^>]*?.*?</object>@siu',
            '@<embed[^>]*?.*?</embed>@siu',
            '@<applet[^>]*?.*?</applet>@siu',
            '@<noframes[^>]*?.*?</noframes>@siu',
            '@<noscript[^>]*?.*?</noscript>@siu',
            '@<noembed[^>]*?.*?</noembed>@siu',
          // Add line breaks before and after blocks
            '@</?((address)|(blockquote)|(center)|(del))@iu',
            '@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu',
            '@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu',
            '@</?((table)|(th)|(td)|(caption))@iu',
            '@</?((form)|(button)|(fieldset)|(legend)|(input))@iu',
            '@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu',
            '@</?((frameset)|(frame)|(iframe))@iu',
        ),
        array(
            ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
            "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0",
            "\n\$0", "\n\$0",
        ),
        $text );
    return strip_tags( $text, '<em><strong><br />' );
}
?>
